Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use useSWR in useUpdateUsdcBalances #2164

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

fionnachan
Copy link
Member

@fionnachan fionnachan commented Dec 24, 2024

We don't need to fetch the USDC address on the child chain every time we want to update the USDC balances because it will never change

Closes FS-1082

@cla-bot cla-bot bot added the cla-signed label Dec 24, 2024
Copy link

vercel bot commented Dec 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
arbitrum-token-bridge ✅ Ready (Inspect) Visit Preview Jan 15, 2025 1:33pm

Base automatically changed from move-balance-updater-syncer-to-hook to master December 27, 2024 13:33
@fionnachan fionnachan marked this pull request as ready for review January 3, 2025 17:38
import { useBalances } from '../useBalances'
import { getProviderForChainId } from '@/token-bridge-sdk/utils'

export async function childChainUsdcAddressFetcher([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do something like this, also renaming the method? I see that it's easier to pass directly from SWR with an array, but it's just harder to read when calling the method.

getChildUsdcAddress({
   parentUsdcAddress,
   parentChainId,
   childChainId
)}

nit: I don't think we need to usd chain in variable names, it's implied. We've been using it without chain on the bridge already and everywhere in the sdk. Might wanna follow the same structure.

})
}

export function useParentChainUsdcAddress() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IF you decide to go with variable names without 'chain', can rename this to useParentUsdcAddress. Otherwise keep consistent.

export function useUpdateUsdcBalances({
walletAddress
}: {
walletAddress: string | undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
walletAddress: string | undefined
walletAddress: Address | undefined

getL2ERC20Address: jest.fn()
}))

const xaiTestnetChainId = 37714555429
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could cast all of these as ChainId here and won't have to do it every time later

])

expect(result).toEqual(CommonAddress.ArbitrumOne.USDC)
expect(result).not.toEqual(CommonAddress.ArbitrumOne['USDC.e'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we don't need to check for USDC.e, if USDC passed then USDC.e must fail (unless we change ArbitrumOne['USDC.e'] to the same value)

import { getProviderForChainId } from '@/token-bridge-sdk/utils'

export async function childChainUsdcAddressFetcher([
_parentChainUsdcAddress,
Copy link
Contributor

@brtkx brtkx Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can do something about _parentChainUsdcAddress, it should not be required for non-Orbit chains, so we should be able to just call the method without specifying parent USDC address and rely on chain ID only.

Maybe we don't need useParentChainUsdcAddress, we could just make it a util method and use it here as well?

updateUsdcBalances()
return
}

latestTokenBridge?.current?.token?.updateTokenData(selectedToken.address)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking here, can we maybe call updateUSDCBalances in updateTokenData directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supposedly, i think it requires some exploration and so i haven't created any tickets for it or dealt with it on this PR as it's out of scope

chrstph-dvx
chrstph-dvx previously approved these changes Jan 7, 2025
brtkx
brtkx previously approved these changes Jan 8, 2025
chrstph-dvx
chrstph-dvx previously approved these changes Jan 8, 2025
brtkx
brtkx previously approved these changes Jan 8, 2025
})
}

export function getParentUsdcAddress(parentChainId: number) {
Copy link
Member Author

@fionnachan fionnachan Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use the CommonAddress object directly if we use chain ids as keys instead of the names Ethereum, Sepolia etc

however such refactoring will involve many files so i'm not doing it on this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants